<div class="layui-fluid">
      <div class="layui-row">
      <form class="layui-form" action="">
        <div class="layui-form-item layui-form-text">
          <label class="layui-form-label">商品规格</label>
          <div class="layui-input-block">
              <button type="button" class="layui-btn" id="attr_add">增加</button> 
          </div>
        </div>
        <div id="shop_attr">
          {foreach name="specs" item="row" key="k" }
              <div class="layui-form-item">
              <label class="layui-form-label"></label>
              <div class="layui-input-inline" style="width: 600px;">
                <input type="text" name="spece_title[]" required  lay-verify="required" value="{$k}" placeholder="属性名" autocomplete="off" class="layui-input" style="width: 30%;display: inline-block;">
                <input type="text" name="spece_values[]" required  lay-verify="required" placeholder="属性值" autocomplete="off" class="layui-input" value="{:implode(',',$row)}" style="width: 50%;display: inline-block;">
                <a onclick="del_attr(this)" class="layui-btn layui-btn-small layui-btn-danger">删除</a>
              </div>
            </div>
          {/foreach}
        </div>
        <div class="layui-form-item">
          <div class="layui-input-block">
            <input type="hidden" name="goods_id" value="{$goods_id}">
            <button class="layui-btn" lay-submit lay-filter="add">发布</button>
          </div>
        </div>
      </form>
    </div>
  </div>
 <style>
   body{
    background: #fff;
   }
 </style>
 <script id="shop_attr_item" type="text/html">
   <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <div class="layui-input-inline" style="width: 600px;">
        <input type="text" name="spece_title[]" required  lay-verify="required" value="颜色" placeholder="属性名" autocomplete="off" class="layui-input" style="width: 30%;display: inline-block;">
        <input type="text" name="spece_values[]" required  lay-verify="required" placeholder="属性值" autocomplete="off" class="layui-input" value="红色,黑色,白色" style="width: 50%;display: inline-block;">
        <a onclick="del_attr(this)" class="layui-btn layui-btn-small layui-btn-danger">删除</a>
      </div>
    </div>
 </script>
<script>
//Demo
layui.use(['form','layedit','upload'], function(){
  var form = layui.form;
  var upload = layui.upload;
  var layedit = layui.layedit;

  $('#attr_add').click(function(event) {
      $('#shop_attr').append($('#shop_attr_item').html());
  });

  
  //监听提交
  form.on('submit(add)', function(data){


    $.post('{:url('admin/goods/add_sku')}', data.field, function(data, textStatus, xhr) {
      // if(data.code){
      //   layer.alert(data.msg, {icon: 6},function(){
      //     xadmin.close();
      //     parent.location.reload();
      //   });
      // }else{
      //   layer.msg(data.msg, function(){});
      // }
      /*optional stuff to do after success */
    });
    // console.log(data.field)
    // layer.msg(JSON.stringify(data.fsield));
    return false;
  });
});

function del_attr(obj) {
  $(obj).parents('.layui-form-item').remove();
}
</script>
      